<?php

class MW_Simplenews_Block_Adminhtml_News_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{

  protected function _prepareForm()
  {
      $form = new Varien_Data_Form();
      $this->setForm($form);
      $form->setHtmlIdPrefix('mw_');
      $fieldset = $form->addFieldset('simplenews_form', array('legend'=>Mage::helper('simplenews')->__('Item information')));
      
      $fieldset->addField('title', 'text', array(
          'label'     => Mage::helper('simplenews')->__('Title'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'title',
      ));

      $fieldset->addField('url_key', 'text', array(
          'label'     => Mage::helper('simplenews')->__('url_key'),
          'required'  => false, 
          'name'      => 'url_key',
	  ));
		
      $fieldset->addField('status', 'select', array(
          'label'     => Mage::helper('simplenews')->__('Status'),
          'required'  => true,
          'name'      => 'status',
          'values'    => array(
              array(
                  'value'     => 1,
                  'label'     => Mage::helper('simplenews')->__('Enabled'),
              ),

              array(
                  'value'     => 2,
                  'label'     => Mage::helper('simplenews')->__('Disabled'),
              ),
          ),
      ));

      $fieldset->addField('category_id', 'select', array(
          'label'     => Mage::helper('simplenews')->__('Category'),
          'name'      => 'category_id',
          'required'  => 'true',
          'values'    =>  Mage::helper('simplenews')->getCategoryOptionValues(true),
      ));

      $fieldset->addField('images', 'file', array(
          'label'     => Mage::helper('simplenews')->__('Images'),
          'required'  => false,
          'name'      => 'images',
      ));
     
      $fieldset->addField('summary', 'editor', array(
          'name'      => 'summary',
          'label'     => Mage::helper('simplenews')->__('Summary'),
          'title'     => Mage::helper('simplenews')->__('Summary'),
          'style'     => 'width:400px; height:120px;',
          'wysiwyg'   => false,
          'required'  => true,
      ));

      $fieldset->addField('content', 'editor', array(
          'name'      => 'content',
          'label'     => Mage::helper('simplenews')->__('Content'),
          'title'     => Mage::helper('simplenews')->__('Content'),
          'style'     => 'width:400px; height:120px;',
          'wysiwyg'   => true,
          'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
          'required'  => true,
      ));
     
      // var_dump(Mage::registry('simplenews_data')); die();

      if ( Mage::getSingleton('adminhtml/session')->getSimplenewsData() )
      {
          $form->setValues(Mage::getSingleton('adminhtml/session')->getSimplenewsData());
          Mage::getSingleton('adminhtml/session')->setSimplenewsData(null);
      } elseif ( Mage::registry('simplenews_data')) {
          $form->setValues(Mage::registry('simplenews_data')->getData());
      }
      
      return parent::_prepareForm();
  }
}